package com.example.springboot008webmvcconfigurer.Interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @description: TODO
 * @author: uu
 * @data: 2023/7/4 上午 10:14
 * @version: v1.0
 */
public class LoginInterceptor implements HandlerInterceptor {
    private List<String> permitUser  = new ArrayList<>();

    public LoginInterceptor() {
        permitUser = Arrays.asList("cms","yd");
    }
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String loginUser = request.getParameter("loginUser");
        System.out.println("登录拦截器");
        if (StringUtils.hasText(loginUser) && permitUser.contains(loginUser)){
            return true;
        }
        return false;
    }
}
